//
//  Macros.h
//  WonderNote
//
//  Created by wangdianlei on 15/4/5.
//  Copyright (c) 2015年 iWonder. All rights reserved.
//

#ifndef Macros_h
#define Macros_h

#define USER_DEFAULT [NSUserDefaults standardUserDefaults]

#define DEFINE_SINGLETON_HEADER(className) \
\
+ (className *)shared##className;

#define DEFINE_SINGLETON_IMPLEMENTATION(className) \
\
static className *shared##className = nil; \
\
+ (className *)shared##className { \
    static dispatch_once_t once; \
    dispatch_once(&once, ^{ \
        shared##className = [[super allocWithZone:NULL] init]; \
    }); \
    return shared##className; \
} \
\
+ (id)allocWithZone:(NSZone *)zone { \
    return [self shared##className]; \
} \
\
- (id)copyWithZone:(NSZone *)zone { \
    return self; \
}

#define GET_CELL(cellType, cellName) (cellType *)[tableView dequeueReusableCellWithIdentifier:cellName]; \
if (cell == nil) { \
    UINib *nib = [UINib nibWithNibName:cellName bundle:nil]; \
    [tableView registerNib:nib forCellReuseIdentifier:cellName]; \
    cell = (cellType*)[tableView dequeueReusableCellWithIdentifier:cellName]; \
}



#define ADD_LINE    UIView *viewLine = [UIView new];\
[self addSubview:viewLine];\
viewLine.backgroundColor =  RGBCOLOR(235,235,235);\
[viewLine mas_makeConstraints:^(MASConstraintMaker *make) {\
    make.top.equalTo(self.mas_top);\
    make.width.mas_equalTo(ScreenWidth);\
    make.height.mas_equalTo(.5);\
    make.left.equalTo(self.mas_left);\
}];\


#define GET_SYSTEM_CELL(cellType, cellName) [tableView dequeueReusableCellWithIdentifier:cellName]; \
if (cell == nil) { \
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyle##cellType reuseIdentifier:cellName]; \
}

#define ARRAY_INIT(NAME) - (NSMutableArray *)NAME { \
    if (_##NAME == nil) { \
        _##NAME = [[NSMutableArray alloc] init]; \
    } \
    return _##NAME; \
}

#define VALIDATE_DATA_AND_CODE(DICT) if (DICT == nil) { \
[ViewFactory showErrorStrMsg:NETWORK_ERR]; \
return; \
} \
NSInteger code = [[DICT objectForKey:@"code"] integerValue]; \
if (![DataValidate validateCode:code]) { \
    [ViewFactory showInfoMsg:[DICT objectForKey:@"msg"]]; \
    return; \
}


#define GOTOROOT   AppDelegate *delegete = (AppDelegate *) \[UIApplication sharedApplication].delegate;\
BaseTabBarController *tab = (BaseTabBarController *) delegete.window.\rootViewController;\
[self.navigationController popToRootViewControllerAnimated:YES];


#define endTableRefreshing(table) [table.header endRefreshing];[table.footer endRefreshing];



#endif
